home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / dbms_mag / 9102 / delta_mi.feb next >
Text File  |  1990-12-21  |  2KB  |  93 lines

  1. Listing 1
  2.  
  3.  
  4. {
  5. Program Name:    delta_mins.4gl
  6.  
  7. Description:    Function which calculates the
  8.         time difference in minutes
  9.         between any two date/times. The
  10.         input parameters are a start
  11.         date, start hour. start minute,
  12.         and end date, end hour, and end
  13.         minute.
  14.         The variable 'time_diff' is
  15.         passed back with the total time
  16.         difference in minutes.
  17.  
  18.  
  19. Revision:    Version 1.0
  20. Author:        Debra L. McCusker
  21. }
  22.  
  23. DEFINE time_diff    INTEGER
  24.  
  25. FUNCTION delta_mins(date1, hour1, min1, date2, hour2, min2)
  26.  
  27. DEFINE date1            DATE
  28. DEFINE hour1             INTEGER
  29. DEFINE min1            INTEGER
  30. DEFINE date2            DATE
  31. DEFINE hour2            INTEGER
  32. DEFINE min2            INTEGER
  33.  
  34. DEFINE strt_yr            INTEGER
  35. DEFINE strt_mo            INTEGER
  36. DEFINE strt_day            INTEGER
  37. DEFINE end_yr            INTEGER
  38. DEFINE end_mo            INTEGER
  39. DEFINE end_day            INTEGER
  40. DEFINE incr1            INTEGER
  41. DEFINE incr2            INTEGER
  42. DEFINE incr3            INTEGER
  43.  
  44. {   Time Difference Calculation -- the normal working day
  45. is from 8:00 AM to 5:00 PM. The time difference calculation
  46. will follow these rules: If the starting time and completion
  47. time occur on the same day, then the starting hours/mins and
  48. ending hours/mins will simply be used to figure the time
  49. difference. If the time difference spans days, then the start
  50. time is subtracted from 1700 hours (5:00 PM) to get the time
  51. increment for the first day. All complete days between the
  52. start and end are treated as 9 hours (540 min) each. The end
  53. increment will be calculated by having 800 hours (8:00 AM)
  54. subtracted from the completion time.
  55. }
  56.  
  57. LET start_yr = YEAR(date1)
  58. LET start_mo = MONTH(date1)
  59. LET start_day = DAY(date1)
  60. LET end_yr = YEAR(date2)
  61. LET end_mo = MONTH(date2)
  62. LET end_day = DAY(date2)
  63.  
  64. IF (start_yr = end yr) AND (strt_mo = end_mo)
  65. THEN
  66.     IF strt_day = end_day
  67.     THEN
  68.       LET time_diff = (60-min1) + (hour2-(hour1+)) * 60+min2
  69.     ELSE
  70.       LET incr1 = (60-min1) + (17-(hour1+1) * 60
  71.       LET incr2 = ((end_day - 1) - strt_day) * 540
  72.       LET incr3 = (hour2 -8) * 60 + min2
  73.  
  74.       LET time_diff = incr1 + incr2 + incr3
  75.     END IF
  76. ELSE
  77. {
  78. ( If the time diff spans either months or years -- to get the
  79. time difference, must get # mins to end of the current day, then
  80. the # complete days between date1 and date2, then # mins left on
  81. the final day.
  82. }
  83.     LET incr1 = (60 - min1) + (17 - (hour1 + 1)) * 60
  84.     LET incr2 = ((date2 - 1) - date1) * 540
  85.     LET incr3 = (hour2 - 8) * 60 + min2
  86.  
  87.     LET time_diff = incr1+ incr2 + incr3
  88. END IF
  89.  
  90. RETURN time_diff
  91.  
  92. END FUNCTION
  93.